package cn.zjj.exception;

import cn.zjj.enums.GlobalErrorCode;
import lombok.Data;

@Data
public class GlobalCustomException extends RuntimeException{

    private String errorMessage;
    private String errorCode;


    public GlobalCustomException() {
        super();
    }

    public GlobalCustomException(String errorMessage, String errorCode) {
        super(errorMessage);//public RuntimeException(String message) { super(message); }
        this.errorMessage = errorMessage;
        this.errorCode = errorCode;
    }
    //调用的时候形参填写 枚举的常量,枚举会返回对应的message和code到此处,赋值给字段,然后被全局异常中的自定义异常捕捉方法异常捕捉,
    public GlobalCustomException(GlobalErrorCode globalErrorCode) {
        super(globalErrorCode.getMessage());//public RuntimeException(String message) { super(message); }
        this.errorMessage = globalErrorCode.getMessage();
        this.errorCode = globalErrorCode.getCode();
    }
}
